layui.use(['form','layer','laydate','util'],function (){
    let form = layui.form,layer = layui.layer,laydate = layui.laydate,util = layui.util;

    let dateElem = $('.form-dateElem');
    //渲染日期模块，最大日期为当前日期
    layui.each(dateElem,function () {
        laydate.render({
            elem:this,
            //最小的日期比今天小几天
            min:0,
        })
    })
})

/**
* @author: ChengJW
* @params:
* @return:
* @date: 2021/11/11
* @description: 初始化部分借阅信息
*/
$(function (){
    $("#bwDt").val(layui.util.toDateString(new Date(),'yyyy-MM-dd'));
    $("#bwCmRegistId").val(getValue("companyRegistId"));
    $("#bwCmNm").val(getValue("companyName"));
    $("#bwCmCreditCode").val(getValue("companyCreditCode"));
    $("#bwBussId").val(getValue("companyBussId"));
    $("#bwCmArchType").val(getValue("companyType"));
    $("#bwCmCheckDt").val(getValue("companyCheckDt"));
    $("#bwCmTotalNum").val(getValue("companyAresTolNum"));
    $("#bwCode").val(getValue("companyCode"));
});

/**
* @author: ChengJW
* @params:
* @return:
* @date: 2021/11/11
* @description: 放弃按钮
*/
function quitAddReadInfo() {
    //获取当前弹窗的索引，并关闭；parent 是 layui 定义的全局变量
    let index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}

/**
* @author: ChengJW
* @params:
* @return:
* @date: 2021/11/11
* @description: 新增借阅信息
*/
function insertReadInfo() {
    //注册号
    let bwCmRegistId = $("#bwCmRegistId").val();
    //企业名称
    let bwCmNm = $("#bwCmNm").val();
    //信用代码
    let bwCmCreditCode = $("#bwCmCreditCode").val();
    //档案类型
    let bwCmArchType =  $("#bwCmArchType").val();
    //核准日期
    let bwCmCheckDt = $("#bwCmCheckDt").val();
    //页数
    let bwCmTotalNum = $("#bwCmTotalNum").val();
    //出借人姓名
    let bwRealNm = $("#bwRealNm").val();
    //出借人机关代码
    let bwCode = $("#bwCode").val();
    //出借日期
    let bwDt = $("#bwDt").val();
    //借阅人
    let bwReadNm = $("#bwReadNm").val().trim();
    //借阅类型
    let bwType = $("select[name = 'bwType']").val();
    //归还日期
    let bwReadDt = $("#bwReadDt").val().trim();
    //借阅说明
    let bwDesc = $("#bwDesc").val().trim();
    //业务编号
    let bwBussId = $("#bwBussId").val();

    //借阅人不能为空
    if (valueIsEmpty(bwReadNm)){
        layer.msg("借阅人不能为空!",{icon:0,time: 1500});
        return;
    }
    if (valueIsEmpty(bwReadDt)){
        layer.msg("归还日期不能为空!",{icon:0,time: 1500});
        return;
    }
    let readJsonData = {
        "bwCmRegistId" : bwCmRegistId,
        "bwCmNm" : bwCmNm,
        "bwCmCreditCode" : bwCmCreditCode,
        "bwBussId" : bwBussId,
        "bwCmArchType" : bwCmArchType,
        "bwCmCheckDt" : bwCmCheckDt,
        "bwCmTotalNum" : bwCmTotalNum,
        "bwRealNm" : bwRealNm,
        "bwCode" : bwCode,
        "bwDt" : bwDt,
        "bwReadNm" : bwReadNm,
        "bwReadDt" : bwReadDt,
        "bwDesc" : bwDesc,
        "bwType" : bwType

    }
    sendAjax("/archivesReadOut/readInfo/addReadInfo",readJsonData,function (result){
        if (valueIsEqual(result.code,"00")){
            quitAddReadInfo();
        }else if (valueIsEqual(result.code,"02")){
            layer.msg(result.data,{icon:5,time: 1500});
        }
    });
}